<template>
  <div class="tab_user" @click="lookUser">
    <div class="city" v-if="city">
      <template v-if="$slots.avatar">
        <!-- <el-image :src="baseUrl + info.reviewerAvatar" lazy-load></el-image> -->
        
        <slot name="avatar" />
      </template>
      <template v-else>
        <span>{{user.city&&user.city.length>2?user.city.slice(0,2):user.city}}</span>
        <template v-if="getTags(user.tags)">
          <div class="tag_bg"></div>
          <span class="tag">{{getTags(user.tags)}}</span>
        </template>
      </template>
    </div>
    <div class="">
      <div class="name">
        <span :class="showClass()" :title="user.customerName || user.name">{{showName(user.customerName)||''}}</span>
        <img src="@/assets/images/male.png" alt="" v-if="user.gender == '男' || user.gender == 1" />
        <img src="@/assets/images/female.png" alt="" v-else-if="user.gender == '女' || user.gender == 2">
        <img src="@/assets/images/unknown.png" alt="" v-else>
        <img src="@/assets/images/star.png" alt="" v-if="user.markTag == 2">
        <img src="@/assets/images/loss.png" alt="" v-if="user.markTag == 4">
        <img src="@/assets/images/invalid.png" alt="" v-if="user.markTag == 3">
      </div>
      <div class="mobile">
        {{user.customerPhone||user.phone||''}}
      </div>
    </div>
  </div>
</template>
<script>
import { broadcast,showToast } from "@/common/util";
export default {
  name: "TabUser",
  props: {
    user: {
      type: Object,
      default: () => {
        return {};
      },
    },
    city: {
      type: Boolean,
      default: true,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    isCustom:{
      type: Boolean,
      default: false,
    }
  },
  data() {
    return {
      showDialog: false,
    };
  },
  mounted() {},
  methods: {
    // 查看用户信息
    lookUser() {
      let row = this.user;
      
      if(this.isCustom){
        this.$emit('click')
        return false;
      }

      if(!row.id || row.id == null){
        showToast({
          message:'缺少参数线索id'
        })
        return false;
      }
      
      if (!this.disabled) {
        broadcast("userDetail", row);
        return false;
      }
    },

    // 展示用户姓名
    showName(str) {
      let o = str;
      if (!str) {
        return "";
      }
      if (str.length > 3) {
        o = str.slice(0, 3) + "...";
      }
      return o;
    },

    // 展示class
    showClass() {
      let row = this.user;
      //user.markTag != 2 && (user.overdueDays == 0 || user.overdueDays == 1)
      if (row.pageType != 2 && row.pageType != 5) {
        return "";
      }

      if (row.markTag != 2 && row.overdueDays <= 1) {
        return "cred";
      }
    },

    // 处理标签字段
    getTags(str) {
      if (!str) {
        return false;
      }
      let arr = str.split(":");
      return arr[0];
    },
  },
};
</script>
<style lang="scss" scoped>
.tab_user {
  display: flex;
  align-items: center;
  cursor: pointer;
  .city {
    position: relative;
    width: 36px;
    height: 36px;
    background: #167fff;
    border-radius: 4px;
    font-size: 14px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff !important;
    text-align: center;
    line-height: 36px;
    margin-right: 7px;
    overflow: hidden;
    .tag_bg {
      position: absolute;
      width: 40px;
      height: 30px;
      transform: rotate(-45deg);
      background: rgba(254, 174, 77, 1);
      box-shadow: 0px 2px 3px 0px rgba(15, 103, 212, 0.35);
      left: -24px;
      top: -15px;
      text-align: center;
      line-height: 10px;
      z-index: 1;
    }
    .tag {
      position: absolute;
      left: 2px;
      top: 1px;
      font-size: 12px;
      z-index: 2;
      line-height: 12px;
      zoom: 0.8;
    }
  }
  .name {
    display: flex;
    align-items: center;
    font-size: 14px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #167fff;
    img {
      width: 14px;
      height: 14px;
      margin-left: 7px;
    }
    .cred {
      color: #f00;
    }
  }
  .mobile {
    font-size: 12px;
    font-family: DIN-Regular, DIN;
    font-weight: 400;
    color: #999999;
    margin: 0;
    padding: 0;
  }
}
.dialog_btn {
  .btn {
    width: 88px;
    height: 32px;
    border-radius: 4px;
    border: 0;
    font-size: 14px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    cursor: pointer;
    margin-left: 16px;
  }
  .btn:hover {
    opacity: 0.8;
  }
  .btn_primary {
    background: #cce2ff;
    color: #167fff;
  }
  .btn_warning {
    background: #ffe3cc;
    color: #ff8f2e;
  }
  .btn_danger {
    background: #ffcccc;
    color: #ff5e59;
  }
}
</style>